package com.frank.loadinglibrary.utils;

import ohos.agp.components.AttrSet;
import ohos.agp.utils.Color;

/**
 * @author SUQI
 * @date 2021/5/24
 * @description
 **/
public class AttrHelper {

    public static String getStringValue(AttrSet attrSet, String key, String defValue) {
        if (null != attrSet) {
            if (attrSet.getAttr(key).isPresent()) {
                return attrSet.getAttr(key).get().getStringValue();
            }
        }
        return defValue;
    }

    public static int getIntegerValue(AttrSet attrSet, String key, int defValue) {
        if (null != attrSet) {
            if (attrSet.getAttr(key).isPresent()) {
                return attrSet.getAttr(key).get().getIntegerValue();
            }
        }
        return defValue;
    }

    public static boolean getBooleanValue(AttrSet attrSet, String key, boolean defValue) {
        if (null != attrSet) {
            if (attrSet.getAttr(key).isPresent()) {
                return attrSet.getAttr(key).get().getBoolValue();
            }
        }
        return defValue;
    }

    public static float getFloatValue(AttrSet attrSet, String key, float defValue) {
        if (null != attrSet) {
            if (attrSet.getAttr(key).isPresent()) {
                return attrSet.getAttr(key).get().getFloatValue();
            }
        }
        return defValue;
    }

    public static long getLongValue(AttrSet attrSet, String key, long defValue) {
        if (null != attrSet) {
            if (attrSet.getAttr(key).isPresent()) {
                return attrSet.getAttr(key).get().getLongValue();
            }
        }
        return defValue;
    }

    public static int getDimensionValue(AttrSet attrSet, String key, int defValue) {
        if (null != attrSet) {
            if (attrSet.getAttr(key).isPresent()) {
                return attrSet.getAttr(key).get().getDimensionValue();
            }
        }
        return defValue;
    }

    public static Color getColorValue(AttrSet attrSet, String key, Color defValue) {
        if (null != attrSet) {
            if (attrSet.getAttr(key).isPresent()) {
                return attrSet.getAttr(key).get().getColorValue();
            }
        }
        return defValue;
    }
}
